﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Chaliy.DbPro.Generators.Tests.TextAuthoring.Mocks;
using Chaliy.DbPro.Generators.TextAuthoring;

namespace Chaliy.DbPro.Generators.Tests.TextAuthoring
{
	[TestClass]
	public class TextAuthorTests
	{
		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		public void TestNormalFlowGeneration()
		{
			const string paragraph = "Test Paragraph!";
			
			string result = TextAuthorTests.Generate(paragraph, paragraph.Length);

			Assert.AreEqual(
				paragraph, result
				);
		}

		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		public void TestNormalFlowGenerationLessThenParagraphsLength()
		{
			const string paragraph = "Test Paragraph!";
			const int lenght = 3;

			string result = TextAuthorTests.Generate(paragraph, lenght);

			Assert.AreEqual(
				lenght, result.Length
				);
		}

		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		public void TestNormalFlowGenerationLargerThenParagraphsLength()
		{
			const string paragraph = "Test Paragraph!";
			const int lenght = 100;

			string result = TextAuthorTests.Generate(paragraph, lenght);

			Assert.AreEqual(
				lenght, result.Length
				);
		}

		[TestMethod]
		[DeploymentItem(DeploymentConstants.GeneratorsDll)]
		[ExpectedException(typeof(ArgumentNullException))]
		public void TestConstructorWithEmptyArguments()
		{
			// Expecitn exception here because 
			// author cannot work without paragraph author
			new TextAuthor(null);
		}

		private static string Generate(string paragraph, int length)
		{
			IParagraphAuthor pargraphAuthor = new MockParagraphAuthor(paragraph);

			ITextAuthor textAuthor = new TextAuthor(pargraphAuthor);

			return textAuthor.Generate(length);
		}
	}
}
